package com.scrat.cameraparam;

import android.Manifest;
import android.hardware.Camera;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions (new String[]{
                    Manifest.permission.CAMERA
            }, 99);
        }

        int num = Camera.getNumberOfCameras ();
        Log.i (TAG, "num:" + num);

        for (int i = 0; i < num; i++) {
            Log.i (TAG, "\n\n==========\n\n");
            Camera camera = Camera.open (0);
            Camera.Parameters parameters = camera.getParameters ();
            //获取预览的各种分辨率
            List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes ();
//获取摄像头支持的各种分辨率
            List<Camera.Size> supportedPictureSizes = parameters.getSupportedPictureSizes ();
            List<Integer> spPictureFormats = parameters.getSupportedPictureFormats ();
            List<Integer> spFrameRate = parameters.getSupportedPreviewFrameRates ();
            List<Camera.Size> supportedVideoSizes = parameters.getSupportedVideoSizes ();

            List<int[]> fpsRanges = parameters.getSupportedPreviewFpsRange ();


            Log.i (TAG, "previewSize:======");
            for (Camera.Size size : supportedPreviewSizes) {
                Log.i (TAG, "" + size.width + "x" + size.height);
            }
            Log.i (TAG, "\nPictureSize========\n");
            for (Camera.Size size : supportedPictureSizes) {
                Log.i (TAG, "" + size.width + "x" + size.height);
            }

            Log.i (TAG, "\nPictureFormats========\n");
            for (Integer size : spPictureFormats) {
                Log.i (TAG, "" + size);
            }
            Log.i (TAG, "\nFrameRates========\n");
            for (Integer size : spFrameRate) {
                Log.i (TAG, "" + size);
            }
            Log.i (TAG, "\nVideoSize========\n");
            for (Camera.Size size : supportedVideoSizes) {
                Log.i (TAG, "" + size.width + "x" + size.height);
            }
            Log.i (TAG, "\nfpsRanges========\n");
            for (int[] range : fpsRanges) {
                Log.i (TAG, "" + Arrays.toString (range));
            }

            Log.i (TAG, "\n\n==========\n\n");

            Log.i (TAG, "isAutoExposureLockSupported:" + parameters.isAutoExposureLockSupported ());
            Log.i (TAG, "isAutoWhiteBalanceLockSupported:" + parameters.isAutoWhiteBalanceLockSupported ());
            Log.i (TAG, "isSmoothZoomSupported:" + parameters.isSmoothZoomSupported ());
            Log.i (TAG, "isVideoSnapshotSupported:" + parameters.isVideoSnapshotSupported ());
            Log.i (TAG, "isZoomSupported:" + parameters.isZoomSupported ());
            Log.i (TAG, "isVideoStabilizationSupported:" + parameters.isVideoStabilizationSupported ());

            Log.i (TAG, "getMaxNumDetectedFaces:" + parameters.getMaxNumDetectedFaces ());
            Log.i (TAG, "getMaxZoom:" + parameters.getMaxZoom ());
            Log.i (TAG, "getColorEffect:" + parameters.getColorEffect ());
        }


    }
}
